from PIL import Image
from torch.utils.tensorboard import SummaryWriter
from torchvision import transforms


writer = SummaryWriter("logs")
img = Image.open("深度学习/微信图片_20231108171009.jpg")
trans_totensor = transforms.ToTensor()
img_tensor = trans_totensor(img)
writer.add_image("Totensor",img_tensor)


# 归一化 Normalization
trans_norm = transforms.Normalize([0.6,0.6,0.6],[0.6,0.6,0.6])
img_norm = trans_norm(img_tensor)
print(img_tensor[0][0][0])
print(img_norm[0][0][0])
writer.add_image("Normolize",img_norm,3)


print(img.size)
trans_resize = transforms.Resize((512,512))
img_resize = trans_resize(img)
print(img_resize)
img_resize = trans_totensor(img)
writer.add_image("img_resize",img_resize,1)
writer.close()

img2 = Image.open("data/OIP-C.jpg")
trans_resize_2 = transforms.Resize(50)
trans_Compose = transforms.Compose([trans_resize_2,trans_totensor])
img_resize_2 = trans_Compose(img2)
writer.add_image("Resize",img_resize_2,3)